package com.cet.spring_batch_study.config;

import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.batch.core.configuration.BatchConfigurationException;
import org.springframework.batch.core.configuration.support.DefaultBatchConfiguration;
import org.springframework.batch.core.launch.JobOperator;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.SimpleAsyncTaskExecutor;
import org.springframework.core.task.TaskExecutor;
import org.springframework.transaction.PlatformTransactionManager;

import javax.sql.DataSource;

/**
 * @author NSOC
 */
@Configuration
@RequiredArgsConstructor
public class BatchJobConfig extends DefaultBatchConfiguration {

    private final DataSource batchDatasource;

    @Override
    @NonNull
    protected DataSource getDataSource() {
        return batchDatasource;
    }

//    @Override
//    @NonNull
//    protected String getTablePrefix() {
//        return "STUDY_BATCH_";
//    }

    /**
     * 配置JobLauncher异步运行作业
     *
     * @return
     */
    @Override
    @NonNull
    protected TaskExecutor getTaskExecutor() {
        return new SimpleAsyncTaskExecutor();
    }

    @Override
    public JobOperator jobOperator() throws BatchConfigurationException {
        return super.jobOperator();
    }

    @Override
    protected PlatformTransactionManager getTransactionManager() {
        return super.getTransactionManager();
    }
}
